from scrapy import Selector
import urllib.request


url = "http://news.sina.com.cn/guide/"
content = urllib.request.urlopen(url).read().decode("utf-8","ignore")
selector = Selector(text=content)
perSort = selector.xpath("//div[@class='clearfix']")

for sort in perSort:
    category = sort.xpath("./h3/text()|./h3/a/text()|./h3/span/text()").extract_first()
    print(category)#总分类
    print('>'*10)
    cateList = sort.xpath(".//ul[@class='list01']/li")#分类列表
    for cate in cateList:
        link = cate.xpath("./a/@href").extract_first()
        cateName = cate.xpath("./a/text()").extract_first()
        
        print("\t"+link+"----"+cateName)#分类名+分类链接
